package com.mlink.service;


import com.google.common.collect.Maps;
import com.mlink.common.utils.Utils;
import com.mlink.entity.User;
import com.mlink.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;

/**
 *
 * @author lsh
 * @date 2018/10/15
 * 注:  需要回归接口添加 注解 ：@Transactional(rollbackFor = Exception.class)
 */


@Service
@EnableTransactionManagement
public class UserService  {
    @Autowired(required = false)
    private UserMapper userMapper;

    public User selectByPhone(String phone) {
        return userMapper.selectByPhone(phone);
    }

    @Transactional(rollbackFor = Exception.class)
    public void insert(User user) {
        user.setUserId(Utils.getUUID());
        userMapper.insert(user);
    }

    public List<User> queryAll(String username) {
        HashMap<Object, Object> map = Maps.newHashMap();
        map.put("username",username);
        List<User> users = userMapper.queryAll(map);
        return users;
    }

    public List<User> queryAllForMap(String username, String password) {
        HashMap<Object, Object> map = Maps.newHashMap();
        map.put("username",username);
        map.put("password",password);
        List<User> users = userMapper.queryAll(map);
        return users;
    }
}


